﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMeterParamFrame.Model.DIValueConverters
{
    /// <summary>
    /// 短类型时间转换类
    /// 主来用来转换 各种切换时间
    /// </summary>
    class Converter_ShortTime : IDIDataConverter
    {
        /// <summary>
        /// 可以转换的 DI
        /// </summary>
        private static string[] CONVERTER_DIS = new string[]{
            "04000106","04000107","04000108","04000109"};

        public bool CanConverter(string di)
        {
            return CONVERTER_DIS.Contains(di);
        }

        public string ConvertToUI(string di, string value)
        {
            string newValue = value.Substring(0, 2) + "-" +
                value.Substring(2, 2) + "-" +
                value.Substring(4, 2) + " " +
                value.Substring(6, 2) + "-" +
                value.Substring(8, 2);
            return newValue;
        }

        public string ConvertToLow(string di, string value)
        {
            string[] dates = value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            string newValue = null;

            //处理日期
            string[] days = dates[0].Split('-');
            for (int i = 0; i < days.Length; i++)
                newValue += days[i].PadLeft(2, '0');
            //处理时间
            string[] times = dates[1].Split('-');
            foreach (string s in times)
            {
                newValue += s.PadLeft(2, '0');
            }
            return newValue;
        }

        public bool ValidateValue(string di, string value)
        {
            throw new NotImplementedException();
        }
    }
}
